package com.ruoyi.common.utils;

import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil
{
  private static final Logger logger = Logger.getLogger(StringUtil.class.getName());
  private static final String EMAIL = "^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$";
  private static final String DATE = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$";
  private static final String NUMBER = "^[0-9]+$";
  private static final String MOBILE = "^(1[0-9])\\d{9}$";
  private static final String SCRIPTREG = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
  private static final String STYLEREG = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
  private static final String HTMLREG = "[<>].*";
  private static final String INTEGER = "^[-\\+]?[\\d]*$";
  private static final String DOUBLE = "^[-+]?(\\d+(\\.\\d*)?|(\\.\\d+))([eE]([-+]?([012]?\\d{1,2}|30[0-7])|-3([01]?[4-9]|[012]?[0-3])))?[dD]?$";
  private static final String CHINESE = "[��-��]+$";
  private static final String CONTROL_CHARACTER = "\\s*|\t|\r|\n";
  
  public static String getNullStringVal(String val)
  {
    if (isEmpty(val)) {
      return "";
    }
    return val;
  }
  
  public static boolean isEmpty(String str)
  {
    return !notEmpty(str);
  }
  
  public static String retrievePayIdFromSharaData(String payId)
  {
    if (isEmpty(payId)) {
      return payId;
    }
    String[] colons = payId.split(";");
    for (int i = 0; i < colons.length; i++)
    {
      String s = colons[i];
      if (!isEmpty(s))
      {
        int commapos = payId.indexOf(",");
        if (-1 != commapos)
        {
          String[] splitedPayId = s.split(",");
          return splitedPayId[1];
        }
      }
    }
    return payId;
  }
  
  public static boolean notEmpty(String str)
  {
    return (str != null) && (str.trim().length() > 0) && (!str.toLowerCase().equals("null"));
  }
  
  public static boolean notEmptyStrnull(String str)
  {
    return (str != null) && (str.trim().length() > 0);
  }
  
  public static boolean isEmptyStrnull(String str)
  {
    return !notEmptyStrnull(str);
  }
  
  public static boolean isEmpty(Object object)
  {
    return (object == null) || (object.toString().trim().length() == 0);
  }
  
  public static boolean notEmpty(Object object)
  {
    return !isEmpty(object);
  }
  
  public static String trimString(String str)
  {
    if (str == null) {
      str = "";
    }
    return str.trim();
  }
  
  public static String toStringAndTrim(Object object)
  {
    if (object == null) {
      return "";
    }
    return object.toString().trim();
  }
  
  public static String formatMobile(String mobile)
  {
    if ((mobile == null) || ("".equals(mobile.trim()))) {
      return null;
    }
    String result = mobile.substring(0, 3) + "****" + mobile.substring(7, 11);
    return result;
  }
  
  public static String[] str2StrArray(String str, String splitRegex)
  {
    if (isEmpty(str)) {
      return null;
    }
    return str.split(splitRegex);
  }
  
  public static String[] str2StrArray(String str)
  {
    return str2StrArray(str, ",\\s*");
  }
  
  public static Map<String, String> string2Map(String text, String splitChar)
  {
    Map<String, String> param = new HashMap();
    if ((isEmpty(text)) || (isEmpty(splitChar))) {
      return param;
    }
    String[] stemps = text.split(splitChar);
    String[] temp = null;
    for (int i = 0; i < stemps.length; i++)
    {
      temp = stemps[i].split("=");
      if (temp.length >= 2)
      {
        param.put(temp[0], temp[1]);
        temp = null;
      }
      else
      {
        param.put(temp[0], "");
      }
    }
    return param;
  }
  
  public static String concatMap(Map<String, String> paramMap)
  {
    if (paramMap == null) {
      return "";
    }
    StringBuilder sbuf = new StringBuilder(512);
    Set<Map.Entry<String, String>> set = paramMap.entrySet();
    Iterator<Map.Entry<String, String>> it = set.iterator();
    while (it.hasNext())
    {
      Map.Entry<String, String> entry = (Map.Entry)it.next();
      sbuf.append((String)entry.getKey()).append("=").append((String)entry.getValue()).append("&");
    }
    if (sbuf.length() > 0) {
      sbuf.deleteCharAt(sbuf.length() - 1);
    }
    return sbuf.toString();
  }
  
  public static boolean isNumeric(String str)
  {
    Pattern pattern = Pattern.compile("^[0-9]+$");
    Matcher isNum = pattern.matcher(str);
    if (isNum.matches()) {
      return true;
    }
    return false;
  }
  
  public static boolean isNumeric(String string, int len)
  {
    if (string.length() > len) {
      return false;
    }
    return isNumeric(string);
  }
  
  public static boolean isDate(String strDate)
  {
    Pattern pattern = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
    
    Matcher m = pattern.matcher(strDate);
    if (m.matches()) {
      return true;
    }
    return false;
  }
  
  public static boolean isEmail(String email)
  {
    String str = "^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$";
    Pattern p = Pattern.compile(str);
    Matcher m = p.matcher(email);
    logger.info(m.matches() + "---");
    return m.matches();
  }
  
  public static boolean isMobileNO(String mobiles)
  {
    Pattern p = Pattern.compile("^(1[0-9])\\d{9}$");
    Matcher m = p.matcher(mobiles);
    logger.info(m.matches() + "---");
    return m.matches();
  }
  
  public static boolean isUrl(String url)
  {
    if (isEmpty(url)) {
      return true;
    }
    if ((url.length() < 4) || (!url.trim().substring(0, 4).toLowerCase().equals("http"))) {
      return true;
    }
    return false;
  }
  
  public static int String_length(String value)
  {
    int valueLength = 0;
    String chinese = "[��-��]";
    for (int i = 0; i < value.length(); i++)
    {
      String temp = value.substring(i, i + 1);
      if (temp.matches(chinese)) {
        valueLength += 2;
      } else {
        valueLength++;
      }
    }
    return valueLength;
  }
  
  public static String subStr(String temp, String beginStr, String endStr)
  {
    if ((isEmpty(temp)) || (isEmpty(beginStr)) || (isEmpty(endStr))) {
      return "";
    }
    if ((!temp.contains(beginStr)) || (!temp.contains(endStr))) {
      return "";
    }
    return temp.substring(temp.indexOf(beginStr) + beginStr.length(), temp.indexOf(endStr));
  }
  
  public static String getString(String str, int longth)
  {
    if ((str == null) || (str.trim().length() <= 0)) {
      return "";
    }
    if (str.length() > longth) {
      return str.substring(0, longth);
    }
    return str;
  }
  
  public static String double2String(double d, int fNumber)
  {
    if (fNumber < 0) {
      fNumber = 0;
    }
    String pattern = null;
    switch (fNumber)
    {
    case 0: 
      pattern = "#0";
      break;
    default: 
      pattern = "#0.";
      StringBuffer b = new StringBuffer(pattern);
      for (int i = 0; i < fNumber; i++) {
        b.append('0');
      }
      pattern = b.toString();
    }
    DecimalFormat formatter = new DecimalFormat();
    formatter.applyPattern(pattern);
    String value = formatter.format(d);
    return value;
  }
  
  public static Map<String, String> convertMap(String responseContent, String splitChar)
    throws Exception
  {
    Map<String, String> retMap = new HashMap();
    if ((responseContent == null) || ("".equals(responseContent))) {
      return null;
    }
    String[] results = responseContent.split(splitChar);
    for (String stemp : results)
    {
      String[] maps = stemp.split("=");
      if ((maps != null) && (maps.length >= 1)) {
        if (maps.length >= 2) {
          retMap.put(maps[0], maps[1]);
        } else {
          retMap.put(maps[0], "");
        }
      }
    }
    return retMap;
  }
  
  public static String retMerchantString(Map map)
  {
    String ret = "";
    Iterator entries = map.entrySet().iterator();
    
    String name = "";
    String value = "";
    while (entries.hasNext())
    {
      Map.Entry entry = (Map.Entry)entries.next();
      name = (String)entry.getKey();
      Object valueObj = entry.getValue();
      if (null == valueObj)
      {
        value = "";
      }
      else
      {
        value = valueObj.toString();
        try
        {
          value = URLEncoder.encode(value, "UTF-8");
        }
        catch (Exception e) {}
      }
      if (ret.length() <= 0) {
        ret = name + "=" + value;
      } else {
        ret = ret + "&" + name + "=" + value;
      }
    }
    return ret;
  }
  
  public static String map2String(Map map)
  {
    String ret = "";
    if ((map == null) || (map.isEmpty())) {
      return ret;
    }
    Iterator entries = map.entrySet().iterator();
    
    String name = "";
    String value = "";
    while (entries.hasNext())
    {
      Map.Entry entry = (Map.Entry)entries.next();
      name = (String)entry.getKey();
      Object valueObj = entry.getValue();
      if (null == valueObj)
      {
        value = "";
      }
      else if ((valueObj instanceof String[]))
      {
        String[] values = (String[])valueObj;
        for (int i = 0; i < values.length; i++) {
          value = values[i] + ",";
        }
        value = value.substring(0, value.length() - 1);
      }
      else
      {
        value = valueObj.toString();
      }
      ret = ret + name + "=" + value + ";";
    }
    return ret;
  }
  
  public static String printMap(Map<String, String> map)
  {
    String ret = "";
    if (map == null) {
      return ret;
    }
    Iterator<String> iterator = map.keySet().iterator();
    while (iterator.hasNext())
    {
      String key = (String)iterator.next();
      String value = (String)map.get(key);
      if (ret.length() > 0) {
        ret = ret + ";";
      }
      ret = ret + key + "=" + value;
    }
    return ret;
  }
  
  public static String printMap(Map<String, String> map, String splitString)
  {
    String ret = "";
    if (map == null) {
      return ret;
    }
    Iterator<String> iterator = map.keySet().iterator();
    while (iterator.hasNext())
    {
      String key = (String)iterator.next();
      String value = (String)map.get(key);
      if (ret.length() > 0) {
        ret = ret + splitString;
      }
      ret = ret + key + "=" + value;
    }
    return ret;
  }
  
  public static String showSensitiveParam(Map<String, String> map, boolean safety)
  {
    StringBuilder sbuf = new StringBuilder(128);
    Set<String> set = map.keySet();
    boolean flag = false;
    sbuf.append("[");
    for (Iterator<String> it = set.iterator(); it.hasNext(); flag = true)
    {
      String key = (String)it.next();
      String value = (String)map.get(key);
      if (safety)
      {
        if (("passwd".equals(key)) || ("pass_wd".equals(key)) || ("cvv2".equals(key)) || ("cvv".equals(key))) {
          if ((value == null) || ("".equals(value))) {
            value = "";
          } else {
            value = "******";
          }
        }
        if (value == null) {
          value = "";
        }
        if ((("card_id".equals(key)) || ("cardid".equals(key))) && (value.length() > 6)) {
          value = value.substring(0, 6) + "******";
        }
      }
      if (!flag) {
        sbuf.append(key).append("=").append(value);
      } else {
        sbuf.append(",").append(key).append("=").append(value);
      }
    }
    sbuf.append("]");
    return sbuf.toString();
  }
  
  public static List<String> strToList(String[] obj)
  {
    if ((obj != null) && (obj.length > 0))
    {
      List<String> objList = new ArrayList(Arrays.asList(obj));
      return objList;
    }
    List<String> arrayList = new ArrayList();
    return arrayList;
  }
  
  public static String convertStr(String str, String oldStr)
  {
    return str.replace(oldStr, "");
  }
  
  public static String formatInputParam(String input)
  {
    if ((input == null) || ("".equals(input.trim()))) {
      return input;
    }
    String textStr = "";
    try
    {
      String scriptReg = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
      
      String styleReg = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
      
      String htmlReg = "[<>].*";
      
      Matcher scriptMatcher = Pattern.compile(scriptReg, 2).matcher(input);
      input = scriptMatcher.replaceAll("");
      
      Matcher styleMatcher = Pattern.compile(styleReg, 2).matcher(input);
      input = styleMatcher.replaceAll("");
      
      Matcher htmlMatcher = Pattern.compile(htmlReg, 2).matcher(input);
      input = htmlMatcher.replaceAll("");
      
      textStr = input;
      textStr = textStr.replaceAll("&hellip;&hellip;", "����");
      textStr = textStr.replaceAll("&nbsp;", "").trim();
      textStr = textStr.replaceAll("\"", "");
      textStr = textStr.replaceAll("\r", "");
      textStr.replaceAll("\n", "");
    }
    catch (Exception e) {}
    return textStr;
  }
  
  public static boolean judgeInputParam(String input)
  {
    if ((input == null) || ("".equals(input.trim()))) {
      return true;
    }
    try
    {
      String scriptReg = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
      
      String styleReg = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
      
      String htmlReg = "[<>].*";
      
      Matcher charMatcher = Pattern.compile(".*[<>\\?\\*'\"].*", 2).matcher(input);
      if (charMatcher.matches()) {
        return false;
      }
      Matcher scriptMatcher = Pattern.compile(scriptReg, 2).matcher(input);
      if (scriptMatcher.matches()) {
        return false;
      }
      Matcher styleMatcher = Pattern.compile(styleReg, 2).matcher(input);
      if (styleMatcher.matches()) {
        return false;
      }
      Matcher htmlMatcher = Pattern.compile(htmlReg, 2).matcher(input);
      if (htmlMatcher.matches()) {
        return false;
      }
      return true;
    }
    catch (Exception e)
    {
      logger.warning(" errMsg: " + e.getMessage());
    }
    return false;
  }
  
  public static boolean isEmpty1(String str)
  {
    return !notEmpty1(str);
  }
  
  public static boolean notEmpty1(String str)
  {
    return (str != null) && (str.trim().length() > 0) && (!str.toLowerCase().equals("null"));
  }
  
  public static boolean isEmptyNull(String str)
  {
    return !notEmptyNull(str);
  }
  
  public static boolean notEmptyNull(String str)
  {
    return (str != null) && (str.trim().length() > 0);
  }
  
  public static boolean isEmpyt1(Object obj)
  {
    return !notEmpty1(obj);
  }
  
  public static boolean notEmpty1(Object obj)
  {
    return (obj != null) && (obj.toString().trim().length() > 0);
  }
  
  public static String trimString1(String str)
  {
    if (isEmptyNull(str)) {
      return "";
    }
    return str.trim();
  }
  
  public static String trimObject(Object obj)
  {
    if (isEmpyt1(obj)) {
      return "";
    }
    return obj.toString().trim();
  }
  
  public static boolean isEmail1(String email)
  {
    if (isEmpty1(email)) {
      return false;
    }
    Pattern pattern = Pattern.compile("^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$");
    Matcher mathcer = pattern.matcher(email);
    return mathcer.matches();
  }
  
  public static boolean isDate1(String date)
  {
    if (isEmpty1(date)) {
      return false;
    }
    Pattern pattern = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
    Matcher mathcer = pattern.matcher(date);
    return mathcer.matches();
  }
  
  public static boolean isNumeric1(String number)
  {
    if (isEmpty1(number)) {
      return false;
    }
    Pattern pattern = Pattern.compile("^[0-9]+$");
    Matcher mathcer = pattern.matcher(number);
    return mathcer.matches();
  }
  
  public static boolean isMobile1(String mobile)
  {
    if (isEmpty1(mobile)) {
      return false;
    }
    Pattern pattern = Pattern.compile("^(1[0-9])\\d{9}$");
    Matcher mathcer = pattern.matcher(mobile);
    return mathcer.matches();
  }
  
  public static boolean isInteger(String str)
  {
    Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
    return pattern.matcher(str).matches();
  }
  
  public static boolean isDouble(String str)
  {
    Pattern pattern = Pattern.compile("^[-+]?(\\d+(\\.\\d*)?|(\\.\\d+))([eE]([-+]?([012]?\\d{1,2}|30[0-7])|-3([01]?[4-9]|[012]?[0-3])))?[dD]?$");
    return pattern.matcher(str).matches();
  }
  
  public static boolean isChinese(String str)
  {
    Pattern pattern = Pattern.compile("[��-��]+$");
    return pattern.matcher(str).matches();
  }
  
  public static String getHideMobileNum(String mobile)
  {
    if ((isEmpty1(mobile)) || (!isMobile1(mobile))) {
      return "";
    }
    return mobile.substring(0, 3) + repeat("*", 4) + mobile.subSequence(7, 11);
  }
  
  public static String getHideEmailPrefix(String email)
  {
    if (null != email)
    {
      int index = email.lastIndexOf('@');
      if (index > 0) {
        email = repeat("*", index).concat(email.substring(index));
      }
    }
    return email;
  }
  
  public static String repeat(String src, int num)
  {
    StringBuffer s = new StringBuffer();
    for (int i = 0; i < num; i++) {
      s.append(src);
    }
    return s.toString();
  }
  
  public static int getStrLength(String str)
  {
    if (isEmptyNull(str)) {
      return 0;
    }
    int valueLength = 0;
    String chinese = "[��-��]";
    for (int i = 0; i < str.length(); i++)
    {
      String temp = str.substring(i, i + 1);
      if (temp.matches(chinese)) {
        valueLength += 2;
      } else {
        valueLength++;
      }
    }
    return valueLength;
  }
  
  public static String getSubString(String str, String bstr, String estr)
  {
    if ((isEmptyNull(str)) || (isEmptyNull(bstr)) || (isEmptyNull(estr))) {
      return "";
    }
    if ((!str.contains(bstr)) || (!str.contains(estr))) {
      return "";
    }
    return str.substring(str.indexOf(bstr) + bstr.length(), str.indexOf(estr));
  }
  
  public static String getSubString(String str, int begin, int end)
  {
    if ((isEmptyNull(str)) || (str.length() < end) || (begin < 0) || (end < 0)) {
      return "";
    }
    return str.substring(begin, end);
  }
  
  public static String getSubString(String str, int index)
  {
    if ((isEmptyNull(str)) || (str.length() < index) || (index < 0)) {
      return "";
    }
    return str.substring(0, index);
  }
  
  public static List<String> stringToList(String str, String splitregex)
  {
    if ((isEmptyNull(str)) || (isEmptyNull(splitregex))) {
      return null;
    }
    List<String> retlist = new ArrayList();
    String[] strs = str.split(splitregex);
    if (notEmpty1(strs)) {
      for (int i = 0; i < strs.length; i++) {
        retlist.add(strs[i]);
      }
    }
    return retlist;
  }
  
  public static List<String> stringToList(String str)
  {
    if (isEmptyNull(str)) {
      return null;
    }
    return stringToList(str, "\\s*,\\s*");
  }
  
  public static List<String> stringToList(String[] obj)
  {
    if (isEmpyt1(obj)) {
      return null;
    }
    return new ArrayList(Arrays.asList(obj));
  }
  
  public static String[] stringToArray(String str, String spiltregex)
  {
    if (isEmptyNull(str)) {
      return null;
    }
    return str.split(spiltregex);
  }
  
  public static String[] stringToArray(String str)
  {
    if (isEmptyNull(str)) {
      return null;
    }
    return stringToArray(str, "\\s*,\\s*");
  }
  
  public static Map<String, String> stringToMap(String str, String connectors, String splitregex, String defalutchar)
  {
    if ((isEmptyNull(str)) || (isEmptyNull(connectors)) || (isEmptyNull(splitregex)) || (isEmptyNull(defalutchar))) {
      return null;
    }
    Map<String, String> returnMap = new HashMap();
    String[] keyValue = str.split(splitregex);
    String[] temp = null;
    for (int index = 0; index < keyValue.length; index++)
    {
      temp = keyValue[index].split(connectors);
      if (temp.length >= 2)
      {
        returnMap.put(temp[0].trim(), temp[1].trim());
        temp = null;
      }
      else
      {
        returnMap.put(temp[0].trim(), defalutchar);
      }
    }
    return returnMap;
  }
  
  public static Map<String, String> stringToMap(String str, String connectors, String splitregex)
  {
    if ((isEmptyNull(str)) || (isEmptyNull(splitregex)) || (isEmptyNull(connectors))) {
      return null;
    }
    return stringToMap(str, connectors, splitregex, "");
  }
  
  public static Map<String, String> stringToMap(String str, String connectors)
  {
    if ((isEmptyNull(str)) || (isEmptyNull(connectors))) {
      return null;
    }
    return stringToMap(str, connectors, "\\s*;\\s*", "");
  }
  
  public static Map<String, String> stringToMap(String str)
  {
    if (isEmptyNull(str)) {
      return null;
    }
    return stringToMap(str, "\\s*=\\s*", "\\s*;\\s*", "");
  }
  
  public static String mapToString(Map<String, String> map, String connectors, String splitregex)
  {
    if ((isEmpyt1(map)) || (isEmpty1(connectors)) || (isEmpty1(splitregex))) {
      return "";
    }
    StringBuilder sb = new StringBuilder();
    Set<Map.Entry<String, String>> set = map.entrySet();
    Iterator<Map.Entry<String, String>> iterator = set.iterator();
    while (iterator.hasNext())
    {
      Map.Entry<String, String> entry = (Map.Entry)iterator.next();
      sb.append((String)entry.getKey()).append(connectors).append((String)entry.getValue()).append(splitregex);
    }
    if (sb.length() > 0) {
      sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
  }
  
  public static String mapToString(Map<String, String> map, String connectors)
  {
    if ((isEmpyt1(map)) || (isEmpty1(connectors))) {
      return "";
    }
    return mapToString(map, connectors, "&");
  }
  
  public static String mapToString(Map<String, String> map)
  {
    if (isEmpyt1(map)) {
      return "";
    }
    return mapToString(map, "=", "&");
  }
  
  public static String objectMapToString(Map<String, Object> map, String connectors, String splitregex)
  {
    if ((isEmpyt1(map)) || (isEmpty1(connectors)) || (isEmpty1(splitregex))) {
      return "";
    }
    StringBuilder sb = new StringBuilder();
    Set<Map.Entry<String, Object>> set = map.entrySet();
    Iterator<Map.Entry<String, Object>> iterator = set.iterator();
    String key = "";
    String value = "";
    while (iterator.hasNext())
    {
      Map.Entry<String, Object> entry = (Map.Entry)iterator.next();
      key = (String)entry.getKey();
      Object obj = entry.getValue();
      if (obj == null)
      {
        value = "";
      }
      else if ((obj instanceof String[]))
      {
        String[] values = (String[])obj;
        for (int i = 0; i < values.length; i++) {
          value = values[i] + ",";
        }
        value = value.substring(0, value.length() - 1);
      }
      else
      {
        value = obj.toString().trim();
      }
      sb.append(key).append(connectors).append(value).append(splitregex);
    }
    if (sb.length() > 0) {
      sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
  }
  
  public static String objectMapToString(Map<String, Object> map, String connectors)
  {
    if ((isEmpyt1(map)) || (isEmpty1(connectors))) {
      return "";
    }
    return objectMapToString(map, connectors, "&");
  }
  
  public static String objectMapToString(Map<String, Object> map)
  {
    if (isEmpyt1(map)) {
      return "";
    }
    return objectMapToString(map, "=", "&");
  }
  
  public static String replaceString(String str, String replaced, String replace)
  {
    if (isEmpty1(str)) {
      return "";
    }
    return str.replaceAll(replaced, replace);
  }
  
  public static String replaceString(String str, String replaced)
  {
    if (isEmpty1(str)) {
      return "";
    }
    return replaceString(str, replaced, "");
  }
  
  public static String replaceControlCharacter(String str)
  {
    if (null != str)
    {
      Pattern p = Pattern.compile("\\s*|\t|\r|\n");
      Matcher m = p.matcher(str);
      str = m.replaceAll("");
    }
    return str;
  }
  
  public static String removeSameString(String str)
  {
    Set<String> mLinkedSet = new LinkedHashSet();
    String[] strArray = str.split(" ");
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < strArray.length; i++) {
      if (!mLinkedSet.contains(strArray[i]))
      {
        mLinkedSet.add(strArray[i]);
        sb.append(strArray[i] + " ");
      }
    }
    return sb.toString().substring(0, sb.toString().length() - 1);
  }
  
  public static final String QJToBJChange(String QJStr)
  {
    char[] chr = QJStr.toCharArray();
    String str = "";
    for (int i = 0; i < chr.length; i++)
    {
      chr[i] = ((char)(chr[i] - 65248));
      str = str + chr[i];
    }
    return str;
  }
  
  public static int stringToInt(String s)
  {
    if (notEmptyNull(s)) {
      try
      {
        return Integer.parseInt(s);
      }
      catch (Exception e)
      {
        return 0;
      }
    }
    return 0;
  }
  
  public static float stringToFloat(String s)
  {
    if (notEmptyNull(s)) {
      try
      {
        return Float.parseFloat(s);
      }
      catch (Exception e)
      {
        return 0.0F;
      }
    }
    return 0.0F;
  }
  
  public static double stringToDouble(String s)
  {
    if (notEmptyNull(s)) {
      try
      {
        return Double.parseDouble(s);
      }
      catch (Exception e)
      {
        return 0.0D;
      }
    }
    return 0.0D;
  }
  
  public static long stringToLong(String s)
  {
    if (notEmptyNull(s)) {
      try
      {
        return Long.parseLong(s);
      }
      catch (Exception e)
      {
        return 0L;
      }
    }
    return 0L;
  }
  
  public static String doubleToString(double d, int fNumber)
  {
    if (fNumber < 0) {
      fNumber = 0;
    }
    String pattern = null;
    switch (fNumber)
    {
    case 0: 
      pattern = "#0";
      break;
    default: 
      pattern = "#0.";
      StringBuffer b = new StringBuffer(pattern);
      for (int i = 0; i < fNumber; i++) {
        b.append('0');
      }
      pattern = b.toString();
    }
    DecimalFormat formatter = new DecimalFormat();
    formatter.applyPattern(pattern);
    String value = formatter.format(d);
    return value;
  }
  
  public static String filterString(String source)
  {
    if (isEmpty(source)) {
      return "";
    }
    return source;
  }
  
  public static String filterInputString(String input)
  {
    if (isEmpty1(input)) {
      return input;
    }
    String textStr = "";
    try
    {
      Matcher scriptMatcher = Pattern.compile("<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>", 2).matcher(input);
      input = scriptMatcher.replaceAll("");
      
      Matcher styleMatcher = Pattern.compile("<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>", 2).matcher(input);
      input = styleMatcher.replaceAll("");
      
      Matcher htmlMatcher = Pattern.compile("[<>].*", 2).matcher(input);
      input = htmlMatcher.replaceAll("");
      
      textStr = input;
      textStr = textStr.replaceAll("&hellip;&hellip;", "����");
      textStr = textStr.replaceAll("&nbsp;", "").trim();
      textStr = textStr.replaceAll("\"", "");
      textStr = textStr.replaceAll("\r", "");
      textStr.replaceAll("\n", "");
    }
    catch (Exception e) {}
    return textStr;
  }
  
  public static boolean verifyInputString(String input)
  {
    if (isEmpty1(input)) {
      return true;
    }
    try
    {
      Matcher charMatcher = Pattern.compile(".*[<>\\?\\*'\"].*", 2).matcher(input);
      if (charMatcher.matches()) {
        return false;
      }
      Matcher scriptMatcher = Pattern.compile("<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>", 2).matcher(input);
      if (scriptMatcher.matches()) {
        return false;
      }
      Matcher styleMatcher = Pattern.compile("<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>", 2).matcher(input);
      if (styleMatcher.matches()) {
        return false;
      }
      Matcher htmlMatcher = Pattern.compile("[<>].*", 2).matcher(input);
      if (htmlMatcher.matches()) {
        return false;
      }
      return true;
    }
    catch (Exception e)
    {
      logger.warning(" errMsg: " + e.getMessage());
    }
    return false;
  }
  
  public static List<String> splitSimpleString(String source, char gap)
  {
    List<String> result = new LinkedList();
    if (source == null) {
      return result;
    }
    char[] sourceChars = source.toCharArray();
    int startIndex = 0;int index = -1;
    while (index++ != sourceChars.length) {
      if ((index == sourceChars.length) || (sourceChars[index] == gap))
      {
        char[] section = new char[index - startIndex];
        System.arraycopy(sourceChars, startIndex, section, 0, index - startIndex);
        result.add(String.valueOf(section));
        startIndex = index + 1;
      }
    }
    return result;
  }
  
  public static String maskCardName(String cardName)
  {
    if (isEmpty(cardName)) {
      return "***";
    }
    if (cardName.length() > 1) {
      return cardName.substring(0, 1) + "**";
    }
    return "***";
  }
}
